
var MainPage = function() {
	return {
		init : function() {
			$(".main_menu li div").click(function () {
		        $(".main_menu li div").removeClass('main_menu leftselected');
		        $(this).addClass('main_menu leftselected');
		    }).hover(function () {
		        $(this).addClass("hoverleftselected");
		    }, function () {
		        $(this).removeClass("hoverleftselected");
		    });
		    //点击TOP按钮显示标签
		    $("#topnav .droppopup a").hover(function () {
		        $("#topnav .droppopup a").removeClass('onnav');
		        $(this).addClass('onnav');
		        var Y = $(this).attr("offsetLeft");
		        $(this).find('.popup').show().css('top', ($(this).offset().top + 68)).css('left', $(this).offset().left - ($(this).find('.popup').width() / 2 - 36));
		    }, function () {
		        $("#topnav .droppopup a").removeClass('onnav');
		        $(this).find('.popup').hide();
		    });
		    $(".popup li").click(function () {
		        $('.popup').hide();
		    });
            var  resizeU =function() {
                var divkuangH = $(window).height();
                $(".main-pannel").height(divkuangH - 130);
                $(".navigation").height(divkuangH - 130);
                $("#ContentPannel").height(divkuangH - 130);
            }
            
            resizeU();
            $(window).resize(resizeU);
            
			//手风琴效果
            var Accordion = function (el, multiple) {
                this.el = el || {};
                this.multiple = multiple || false;
                var links = this.el.find('.link');
                links.on('click', { el: this.el, multiple: this.multiple }, this.dropdown)
            }
            Accordion.prototype.dropdown = function (e) {
                //计算高度
                var accordionheight = ($("#accordion").children("ul li").length * 36);
                var navigationheight = $(".navigation").height()
                $('#accordion li').children('.b-children').height(navigationheight - accordionheight - 1);
                $(this).next().slideToggle();
                $(this).parent().toggleClass('open');
                if (!e.data.multiple) {
                    $(this).parent().parent().find('.submenu').not($(this).next()).slideUp().parent().removeClass('open');
                };
            }
			$(".submenu a").click(function () {
                $('.submenu a').removeClass('action');
                $(this).addClass('action');
            })
            var accordion = new Accordion($('#accordion'), false);
            $("#accordion li:first").find('div').trigger("click");//默认第一个展开
            $('.btn-nav-toggle').click(function () {
                if (!$('.btn-nav-toggle').attr('disabled') && !$(this).hasClass("harvest")) {
                    $(this).addClass('harvest');
                    $(".navigation").animate({ width: 0 }, 100);
                    $('.accordion').hide();
                    $(this).find('b').show();
                    $(this).find('i').hide();
                  
                } else {
                    $(this).removeClass('harvest');
                    $(".navigation").animate({ width: 204 }, 100);
                    $('.accordion').show();
                    $(this).find('b').hide();
                    $(this).find('i').show();
                
                }
             }).hover(function () {
                if ($(this).hasClass("harvest")) {
                    $(this).attr('title', '隐藏导航');
                    $(this).removeClass('harvest');
                    $(".navigation").animate({ width: 204 }, 100);
                    $('.accordion').show();
                    $(this).find('b').hide();
                    $(this).find('i').show();
                    $(".navigation").css('position', 'absolute');
                }
             }, function () {
            });
            
            layer.config({
				 title:['提示','background-color:#4A5B79;color:#FFF']
			 });
		    MainPage.serverCurrentTime();
		    //初始化Tab
		    $('#tabs_container').simpleTab();
		    //选择主题颜色
		    $('.skinSelect').click(MainPage.skinSelect);

		},
	    serverCurrentTime: function() {
	    	var now = new Date();
	        var year = now.getFullYear();
	        var month = now.getMonth();
	        var date = now.getDate();
	        var day = now.getDay();
	        var hour = now.getHours();
	        var minu = now.getMinutes();
	        var sec = now.getSeconds();
	        var week;
	        month = month + 1;
	        if (month < 10) month = "0" + month;
	        if (date < 10) date = "0" + date;
	        if (hour < 10) hour = "0" + hour;
	        if (minu < 10) minu = "0" + minu;
	        if (sec < 10) sec = "0" + sec;
	        var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
	        week = arr_week[day];
	        var time = "";
	        time = year + "年" + month + "月" + date + "日" + " " + hour + ":" + minu + ":" + sec;
	        $("#CurrentTime").text(time);
	        var timer = setTimeout("MainPage.ServerCurrentTime()", 1000);
	    },
	    skinSelect:function(){
	    	 var color = $(this).attr('background');
	         $(".main-header").css('background', color);
	         $(".main-footer").css('background', color);
	        
	         $(".popup ul").css('background', color);
	         $(".popup span").css('border-color', "transparent transparent " + color);
			 $(".submenu .action").css('background', color);
			 layer.config({
				 title:['提示','background-color:'+color+';color:#FFF']
			 });
	    }
		    
	}
	    
}();



/* 
请求Ajax 带返回值
*/
function getAjax(url, postData, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        url: webRoot + url,
        data: postData,
        cache: false,
        async: false,
        success: function (data) {
            callBack(data);
            //Loading(false);
        },
        error: function (data) {
            alert("error:" + JSON.stringify(data));
            Loading(false);
        }
    });
}
function AjaxJson(url, postData, callBack) {
    try {
        $.ajax({
            url: RootPath() + url,
            type: "post",
            data: postData,
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.Code == "-1") {
                    Loading(false);
                    alertDialog(data.Message, -1);
                } else {
                    Loading(false);
                    callBack(data);
                }
            },
            error: function (data) {
                Loading(false);
                alertDialog(data.responseText, -1);
            }
        });
    } catch (e) {

    }
}

//=================动态菜单tab标签========================

function linkHiddenMenu(){
    $('.btn-nav-toggle').removeAttr('disabled');
    $('.btn-nav-toggle').removeClass('harvest');
    $('.btn-nav-toggle').trigger("click");
    //点击Tab事件
    $('#tabs_container li').click(function () {
        var id = $(this).attr('id');
        if (id == 'tabs_Imain') {
            $('.btn-nav-toggle').attr('disabled', 'disabled');
            //点击首页（显示导航菜单）
            $(".navigation").css('position', '');
            $(".navigation").css('width', '204');
            $('.accordion').show();
            $('.btn-nav-toggle').addClass('harvest');
            $('.btn-nav-toggle').find('b').hide();
            $('.btn-nav-toggle').find('i').show();
            $('.btn-nav-toggle').attr('title', '');
        } else {
            $('.btn-nav-toggle').removeAttr('disabled');
            //（隐藏导航菜单）
            $(".navigation").css('position', 'absolute');
            $('.btn-nav-toggle').removeClass('harvest');
            $('.btn-nav-toggle').trigger("click");
        }
    });
} 


function addTab(id, title, url, icon, closable) {
	 linkHiddenMenu();
	 $('#tabs_container').simpleTab('add', {
			id : id,
			title : title,
			closable : closable,
			icon : icon,
			url:url
	 });
	 
}
